#include<bits/stdc++.h>
using namespace std;
#define int long long
map<int,int> mp;
priority_queue<int> p;
priority_queue<int,vector<int>,greater<int>> q;
signed main()
{
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0); 
	int t;
	cin>>t;
	while(t--)
	{
		int x;
		cin>>x;
		mp[x]^=1;
		for(auto pos:mp) if(pos.second==1) p.push(pos.first),q.push(pos.first);
		vector<pair<int,int> > v;v.clear();
		int sum1=0,sum2=0; 
		while(!q.empty())
		{
			sum1+=q.top(),sum2+=p.top();
			v.push_back({sum1,sum2});
			q.pop(),p.pop();
		}
		sort(v.begin(),v.end());
		int ans=0;
		int st=v[0].first,ed=v[0].second; 
		for(int i=0;i<v.size();i++)
		{
			if(v[i].first<=ed){ed=max(ed,v[i].second);continue;}
			ans+=(ed-st),st=v[i].first,ed=v[i].second;
		}
		ans+=(ed-st);
		cout<<ans<<"\n";
	}
}
